<!--  -->
<template>
  <div class="app-container">
    <el-form :inline="true" size="small">
      <el-form-item label="模板编号">
        <el-input
          v-model="mId"
          placeholder="请输入分类编号"
          size="small"
        ></el-input>
      </el-form-item>
      <el-form-item label="模板名称">
        <el-input
          v-model="mName"
          placeholder="请输入分类名称"
          size="small"
        ></el-input>
      </el-form-item>

      <el-button icon="el-icon-search" type="primary" size="small" @click
        >搜索</el-button
      >
      <el-button icon="el-icon-refresh" size="small" @click>重置</el-button>
      <el-button icon="el-icon-edit" type="warning" size="small" @click='add'
        >新增</el-button
      >
      <el-button icon="el-icon-delete" type="danger" size="small" @click
        >删除</el-button
      >
      <el-button
        icon="el-icon-notebook-2"
        type="primary"
        size="small"
        @click="toType"
        >专家分类管理</el-button
      >
    </el-form>
    <el-table :data="tableData" border stripe>
      <el-table-column
        type="selection"
        width="60"
        align="center"
      ></el-table-column>

      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 4"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.inHome"
              :active-value="1"
              :inactive-value="2"
              @change
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="index == 3"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.inExp"
              :active-value="1"
              :inactive-value="2"
              @change
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color: #f66"
            @click="deleteCategory(scope.$index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <!-- 添加分栏 -->
    <el-dialog
      title="添加分栏"
      :visible.sync="showEdit"
      width="35%"
      @close="showAdd = false"
    >
      <el-form
        :model="cData"
        ref="form2"
        :rules="rules"
        label-width="100px"
        :inline="false"
        size="normal"
        class="dbox"
      >
        <el-form-item label="专家编号">
          <el-input
            v-model="cData.id"
            style="width: 270px"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="专家名称">
          <el-input
            v-model="cData.name"
            style="width: 270px"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="专家图片">
          <el-image src="" fit="fill" :lazy="true" style="margin-right:10px;width:100px"></el-image>
          <el-image src="" fit="fill" :lazy="true" style="margin-right:10px;width:100px"></el-image>
          <el-image src="" fit="fill" :lazy="true" style="margin-right:10px;width:100px"></el-image>
          
        </el-form-item>
         <el-form-item label="是否推荐至护肤大学首页" class="switchLabel">
          <el-switch v-model="cData.name" :active-value="1" :inactive-value="0" style="width: 270px"/>
        </el-form-item>
         <el-form-item label="是否推荐至专家首页" class="switchLabel">
          <el-switch v-model="cData.name" :active-value="1" :inactive-value="0" style="width: 270px"/>
        </el-form-item>
         <el-form-item label="所属分类">
          <el-input
            v-model="cData.name"
            style="width: 270px"
            clearable
          ></el-input>
        </el-form-item>

         <el-form-item label="专家信息">
          <el-input
            v-model="cData.name"
            style="width: 270px"
            clearable
          ></el-input>
        </el-form-item>
         <el-form-item label="专家标签">
          <el-input
            v-model="cData.name"
            style="width: 270px"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="showAdd = false">取消</el-button>
        <el-button type="primary" @click>提交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getArticle } from "@/api/article";
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      page: 1,
      limit: 10,
      total: 10,
      dialogTitle: "创建",
      showEdit: false,
      cData: {},
      tableData: [
        {
          id: "1",
          name: "1",
          photo: "1",
          inHome: 1,
          inExp: 0,
          type: "1",
          info: "1",
          tabs: "1",
        },
        {
          id: "2",
          name: "2",
          photo: "2",
          inHome: 0,
          inExp: 1,
          type: "2",
          info: "2",
          tabs: "2",
        },
        {
          id: "3",
          name: "3",
          photo: "3",
          inHome: 1,
          inExp: 1,
          type: "3",
          info: "3",
          tabs: "3",
        },
      ],
      rules:{},
      columns: [
        { key: 0, label: `专家编号`, data: "id", width: "80" },
        { key: 1, label: `专家名称`, data: "name" },
        { key: 2, label: `专家图片`, data: "photo" },
        { key: 3, label: `是否推荐至护肤大学首页`, data: "inHome" },
        { key: 4, label: `是否推荐至专家首页`, data: "inExp" },
        { key: 4, label: `所属分类`, data: "type" },
        { key: 4, label: `专家信息`, data: "info" },
        { key: 4, label: `专家标签`, data: "tabs" },
      ],
      artQuery: {
        id: "1",
      },
    };
  },
  created() {
    
  },
  methods: {
    add() {
      this.cData = {};
      this.showEdit = true;
    },
    edit(i) {
      this.cData = i;
      this.showEdit = true;
    },
    toType() {
      this.$router.push('/university/expMode')
    },
    del(i, d) {
      this.$confirm("确认删除所选数据？", "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    sizeChange() {},
    currentChange() {},
  },
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
.switchLabel >>> .el-form-item__label{
    line-height: 20px;
}
</style>
